package com.societyGames.codeAlong.state.codeExercise.view.testCase
{
import com.societyGames.flashForms.CenterScaleTextFieldContainer;
import com.societyGames.flashForms.DirectContainer;
import com.societyGames.flashForms.IChangeSize;
import com.societyGames.flashForms.ZeroOriginContainer;
import com.societyGames.flashForms.basicSkin.SharedTextFields;

import flash.display.DisplayObject;
import flash.text.TextField;

public class TestCaseIcon extends DirectContainer implements IChangeSize
{
  [Embed(source="/../assets/InterfaceAssets.swf", symbol="Success")]
  private static const _successSpriteClass:Class;

  [Embed(source="/../assets/InterfaceAssets.swf", symbol="Fail")]
  private static const _failSpriteClass:Class;

  [Embed(source="/../assets/InterfaceAssets.swf", symbol="Neutral")]
  private static const _readySpriteClass:Class;

  [Embed(source="/../assets/InterfaceAssets.swf", symbol="Exception")]
  private static const _exceptionSpriteClass:Class;


  private var _failSprite:DisplayObject;
  private var _successSprite:DisplayObject;
  private var _readySprite:DisplayObject;
  private var _exceptionSprite:DisplayObject;
  private var _noneTextFieldContainer:CenterScaleTextFieldContainer;

  public function TestCaseIcon(testCaseIndex:int)
  {
    super();

    _failSprite = wrapDisplayObjectInZeroOriginContainer(_failSpriteClass);
    _successSprite = wrapDisplayObjectInZeroOriginContainer(_successSpriteClass);
    _readySprite = wrapDisplayObjectInZeroOriginContainer(_readySpriteClass);
    _exceptionSprite = wrapDisplayObjectInZeroOriginContainer(_exceptionSpriteClass);

    _noneTextFieldContainer = new CenterScaleTextFieldContainer();
    _noneTextFieldContainer.textField = createNoneTextField();
    setTestCaseIndex(testCaseIndex);

    showNone();
  }

  public function showFail():void
  {
    this.item = _failSprite;
  }

  public function showSuccess():void
  {
    this.item = _successSprite;
  }

  public function showReady():void
  {
    this.item = _noneTextFieldContainer; //_readySprite;
  }

  public function showException():void
  {
    this.item = _exceptionSprite;
  }

  public function showNone():void
  {
    this.item = _noneTextFieldContainer;
  }

  private function setTestCaseIndex(testCaseIndex:int):void
  {
    _noneTextFieldContainer.textField.text = testCaseIndex.toString();
  }

  private function createNoneTextField():TextField
  {
    //Create a generic textField.
    var textField:TextField = SharedTextFields.createTextField();
    return textField;
  }

  private function wrapDisplayObjectInZeroOriginContainer(displayObjectClass:Class):DisplayObject
  {
    var centerScaleContainer:ZeroOriginContainer = new ZeroOriginContainer();
    centerScaleContainer.item = DisplayObject(new displayObjectClass());
    return centerScaleContainer;
  }
}
}